package com.authine.cloudpivot.ext.utils;

import com.authine.cloudpivot.ext.constants.AppConst;
import com.authine.cloudpivot.ext.constants.ModelConst;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * @Author: liwei
 * @DateTime: 2021/8/5
 * @Description: TODO
 */
public class TransferFinanceUtil {


    /**
     * 固买组织 关于公司账套有两张表  平台组织表  & 转采供应商表
     * 部分公司可能会在两张表都出现 以组织表为主  此处主要是用于请求金蝶接口
     *
     * @param vendorName
     * @return
     */
    public static String getKingdeeOrgId(String vendorName) {

        if (StringUtils.isBlank(vendorName)) {
            return null;
        }

        String pmVendor = null;
        String trVendor = null;
        //t_organization
        Map<String, Object> organization = JdbcTemplateUtils.builder(AppConst.SYSTEM_MANAGEMENT, ModelConst.T_ORGANIZATION).selectField("*")
                .eq("name", vendorName).queryForMap();

        if (null != organization) {
            pmVendor = String.valueOf(organization.get("id"));
        }

        //t_transfer_vendor
        Map<String, Object> vendor = JdbcTemplateUtils.builder(AppConst.SYSTEM_MANAGEMENT,ModelConst.T_TRANSFER_VENDOR).selectField("*")
                .eq("company_name", vendorName).queryForMap();

        if (null != vendor) {
            trVendor = String.valueOf(vendor.get("id"));
        }

        if (null != pmVendor) {

            return pmVendor;

        } else if (null != trVendor) {

            return "Z" + trVendor;

        }

        return null;
    }
}
